﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;
using l1cs.server.utils;

namespace l1cs.server.clientpackets
{
    public class C_Fight : ClientBasePacket
    {
        private const String _C_FIGHT = "[C] C_Fight";
        private static Logger _log = Logger.getLogger( typeof( C_Fight ).FullName );

        public C_Fight( byte[] abyte0, ClientThread client )
            : base( abyte0 )
        {

            L1PcInstance pc = client.getActiveChar();
            if ( pc.isGhost() )
            {
                return;
            }
            L1PcInstance target = FaceToFace.faceToFace( pc );
            if ( target != null )
            {
                if ( !target.isParalyzed() )
                {
                    if ( pc.getFightId() != 0 )
                    {
                        pc.sendPackets( new S_ServerMessage( 633 ) ); // \f1あなたはすでにほかの人と決闘中です。
                        return;
                    }
                    else if ( target.getFightId() != 0 )
                    {
                        target.sendPackets( new S_ServerMessage( 634 ) ); // \f1すでにほかの人と決闘中です。
                        return;
                    }
                    pc.setFightId( target.getId() );
                    target.setFightId( pc.getId() );
                    target.sendPackets( new S_Message_YN( 630, pc.getName() ) ); // %0%sがあなたと決闘を望んでいます。応じますか？（Y/N）
                }
            }
        }

        override
        public String getType()
        {
            return _C_FIGHT;
        }
    }
}